package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqAppFile;
import com.wtwd.campus.entity.MqUplocadAppFile;
import com.wtwd.campus.service.InjectFeignService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mjy
 * @date 2022/12/12
 * @description
 */
public class UplocaAppFile implements Receiver {

//    *TJ,imei,UPLOADAPPFILE,HHMMSS,type,groupNum,Package,file,fileName,DATE,STATUS#


    @Override
    public String parseMessage(String data) {
        String[] split = data.split(",");
        String imei = split[1];
        String commandNumber = split[3];
        String type = split[4];
        int groupNum = Integer.valueOf(split[5]);
        String date = split[split.length - 2];
        String deviceStatus = split[split.length - 1];
        MqUplocadAppFile mqUplocadAppFile = new MqUplocadAppFile();
        mqUplocadAppFile.setImei(imei);
        mqUplocadAppFile.setCommandNumber(commandNumber);
        mqUplocadAppFile.setType(Integer.valueOf(type));
        mqUplocadAppFile.setGroupNum(groupNum);
        mqUplocadAppFile.setDeviceDate(date);
        mqUplocadAppFile.setDeviceTime(commandNumber);
        mqUplocadAppFile.setDeviceStatus(deviceStatus);
        List<MqAppFile> mqAppFiles = new ArrayList<>();
        if (groupNum>0){
            for (int i = 1; i <= groupNum; i++) {
                String packageName=split[5+3*(i-1)+i];
                String file=split[6+3*(i-1)+i];
                String fileName=split[7+3*(i-1)+i];
                MqAppFile mqAppFile = new MqAppFile();
                mqAppFile.setFile(file);
                mqAppFile.setPackageName(packageName);
                mqAppFile.setFileName(fileName);
                mqAppFiles.add(mqAppFile);
            }
        }
        mqUplocadAppFile.setAppFiles(mqAppFiles);
        InjectFeignService.getIrmFeignClientService().upLoadAppFile(mqUplocadAppFile);
        return imei;
    }



}
